package utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Map;

public class DbConn {
	public Map<String, String> map;

	public DbConn(Map<String, String> map) {
		this.map = map;
	}

	/**
	 * driverClassName=oracle.jdbc.driver.OracleDriver
	url=jdbc:oracle:thin:@10.224.212.73:1521/bjdo
	username=do_trail
	password=do_trail

	 * @return
	 */
	public Connection getConnection() throws Exception {
		Class.forName(map.get("driverClassName"));
		String url = map.get("url");
		String user = map.get("username");
		String password = map.get("password");
		return DriverManager.getConnection(url, user, password);
	}

	public static void closeAll(final ResultSet rs, Statement st, final Connection conn) {
		try {
			if (rs != null)
				rs.close();
		} catch (final SQLException e) {
		}

		try {
			if (st != null)
				st.close();
		} catch (final SQLException e) {
			st = null;
		}

		try {
			if (conn != null)
				conn.close();
		} catch (final SQLException e) {
		}
	}

}
